using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUSLayer;

namespace QuanLyThuVien
{
    public partial class frmThemSach : Form
    {
        public frmThemSach()
        {
            InitializeComponent();
        }

        private void btnTLMoi_Click(object sender, EventArgs e)
        {
            frmTheLoai frm = new frmTheLoai();
            frm.ShowDialog();
        }

        private void btnTGMoi_Click(object sender, EventArgs e)
        {
            frmThemtacgia frm = new frmThemtacgia();
            frm.ShowDialog();
        }

        private void frmThemSach_Load(object sender, EventArgs e)
        {
            try
            {
                IList dsloaisach = LoaiSachBus.LayDanhSach();
                cmbTheLoai.DataSource = dsloaisach;
                cmbTheLoai.ValueMember = "MALOAISACH";
                cmbTheLoai.DisplayMember = "LOAISACH";

                IList dstacgia = TacGiaBus.LayDanhSach();
                cmbTacgia.DataSource = dstacgia;
                cmbTacgia.ValueMember = "MATACGIA";
                cmbTacgia.DisplayMember = "TENTACGIA";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                SachDto sach = new SachDto();
                LoaiSachDto loaisach = (LoaiSachDto)cmbTheLoai.SelectedItem;
                TacGiaDto tacgia = (TacGiaDto)cmbTacgia.SelectedItem;

                sach.TENSACH = txtTensach.Text;
                sach.MALOAISACH = loaisach.MALOAISACH;
                sach.MATACGIA = tacgia.MATACGIA;
                sach.NAMXUATBAN = int.Parse(txtNamXB.Text);
                sach.GIA = int.Parse(txtGia.Text);
                sach.TINHTRANG = false;

                SachBus.Them(sach);
                txtMasach.Text = sach.MASACH.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnBo_Click(object sender, EventArgs e)
        {
            txtTensach.Clear();
            txtNamXB.Clear();
            txtGia.Clear();
        }

        private void btnRefesh_Click(object sender, EventArgs e)
        {
            try
            {
                IList dsloaisach = LoaiSachBus.LayDanhSach();
                cmbTheLoai.DataSource = dsloaisach;
                cmbTheLoai.ValueMember = "MALOAISACH";
                cmbTheLoai.DisplayMember = "LOAISACH";

                IList dstacgia = TacGiaBus.LayDanhSach();
                cmbTacgia.DataSource = dstacgia;
                cmbTacgia.ValueMember = "MATACGIA";
                cmbTacgia.DisplayMember = "TENTACGIA";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}